﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TS.Bussiness;
using TS.Commons;
using TS.Entities;

namespace Tranco.Views
{
    public partial class Config : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ConfigurationBussiness bu = new ConfigurationBussiness();
                var config = bu.GetConfig();

                txtNotify.Text = config.Notify;
                txtPageSize.Text = config.PageSize.ToStringOrDefault();
                txtEmail.Text = config.WebEmail;
                txtWebName.Text = config.WebName;
                txtWebLink.Text = config.WebLink;
                txtTel.Text = config.WebTel;
                txtShortAddress.Text = config.ShortAddress;
                txtAddress.Text = config.Address;
                txtSologan.Text = config.Sologan;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            lblStatus.ForeColor = Color.Red;
            ConfigurationBussiness bu = new ConfigurationBussiness();
           
            Configuration config = new Configuration();
            config.Notify = txtNotify.Text;
            config.PageSize = txtPageSize.Text.ToNumeric();
            config.WebEmail = txtEmail.Text;
            config.WebName = txtWebName.Text;
            config.WebLink = txtWebLink.Text;
            config.WebTel = txtTel.Text;
            config.ShortAddress = txtShortAddress.Text;
            config.Address = txtAddress.Text;
            config.Sologan = txtSologan.Text;

            var result = bu.UpdateConfig(config);

            if (result > 0)
            {
                lblStatus.ForeColor = Color.Blue;
                lblStatus.Text = "Cấu hình thành công";
            }
            else
            {
                lblStatus.Text = "Cấu hình thất bại";

            }
        }
    }
}